﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

namespace SentientGrid
{
    public class GridState
    {
        public string Search { get; set; }
        public double Nd { get; set; }
        public int Rows { get; set; }
        public int Page { get; set; }
        public string Sidx { get; set; }
        public string Sord { get; set; }
        public int Total { get; set; }

        public static GridState CreateFromQueryString(NameValueCollection queryString)
        {
            var gs = new GridState();

            gs.Search = !string.IsNullOrEmpty(queryString["_search"]) ? queryString["_search"] : string.Empty;
            gs.Nd = queryString["Nd"] != null ? Convert.ToDouble(queryString["Nd"]) : 0;
            gs.Rows = queryString["Rows"] != null ? Convert.ToInt32(queryString["Rows"]) : 0;
            gs.Page = queryString["Page"] != null ? Convert.ToInt32(queryString["Page"]) : 0;
            gs.Sidx = !string.IsNullOrEmpty(queryString["sidx"]) ? queryString["sidx"] : string.Empty;
            gs.Sord = !string.IsNullOrEmpty(queryString["sord"]) ? queryString["sord"] : string.Empty;

            return gs;


        }
    }
}
